package com.briup.app02.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.app02.bean.Order;
import com.briup.app02.bean.OrderExample;
import com.briup.app02.bean.extend.OrderExtend;
import com.briup.app02.service.IOrderService;

import com.briup.app02.dao.OrderMapper;
import com.briup.app02.dao.extend.OrderExtendMapper;

@Service
public class OrderServiceImpl implements IOrderService{

	@Autowired
	private OrderMapper orderMapper;
	@Autowired 
	OrderExtendMapper orderExtendMapper;
	
	@Override
	public OrderExtend findById(Long id) {
//		return orderMapper.selectByPrimaryKey(id);
		return orderExtendMapper.findById(id);
	}

	@Override
	public void deleteById(Long id) {
		orderMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void changeStatus(Long id, String status) {
		Order order = findById(id);
		// 设置服务时间
		if(status.equals("已完成")) {
			order.setServiceTime(new Date().getTime());
		}
		order.setStatus(status);
		orderMapper.updateByPrimaryKey(order);
	}

	@Override
	public void submitOrder(Order order) {
		// 初始化:设置订单时间、初始状态
		order.setOrderTime(new Date().getTime());
		order.setStatus("待派单");
		orderMapper.insert(order);
	}

	@Override
	public List<OrderExtend> pageQuery(int page, int pageSize, String status, Long customerId) {
		int pageIndex = (page-1)*pageSize;
		List<OrderExtend> orderExtends = orderExtendMapper.pageQuery(pageIndex, pageSize, status, customerId);
		return orderExtends;
	}

	@Override
	public List<Order> findAll() {
		OrderExample example = new OrderExample();
		List<Order> orders = orderMapper.selectByExample(example);
		return orders;
	}


}